<template>
  <view class="page">
    <view class="select_box">
      <view class="tip">请选择您的企业类型</view>
      <view class="item" v-for="(item, index) in merchantTypeOptions" @click="handleClick(index)">
        <image class="img" :src="item.img" mode="aspectFill"></image>
        <view class="border" v-if="selectIndex == index"></view>
      </view>
    </view>

    <view class="next_btn" @click="next">
      <view class="btn">下一步</view>
    </view>
  </view>
</template>

<script setup>
  import { ref, computed } from 'vue';
  import { onShow, onLoad } from '@dcloudio/uni-app';
  import { useFormStore } from '../../store/form';

  const formStore = useFormStore();
  const { merchantForm } = formStore; // 商户表

  const selectIndex = ref(-1);

  const merchantTypeOptions = [
    {
      id: 1,
      name: '代理商',
      img: '/static/step1_1.png',
    },
    {
      id: 2,
      name: '个人',
      img: '/static/step1_2.png',
    },
    {
      id: 3,
      name: '移动营业厅',
      img: '/static/step1_3.png',
    },
    {
      id: 4,
      name: '品牌商',
      img: '/static/step1_4.png',
    },
  ];

  onLoad(() => {
    console.log('onLoad');
  });

  // 选择
  function handleClick(index) {
    selectIndex.value = index;
    merchantForm.merchantType = merchantTypeOptions[index].id;
    console.log(merchantForm, 'merchantForm >>>');
  }

  // 下一步
  function next() {
    if (!merchantForm.merchantType) {
      uni.showToast({
        title: '请选择企业类型',
        icon: 'none',
      });
    } else {
      uni.navigateTo({
        url: '/pagesB/register/step2',
      });
    }
  }
</script>

<style scoped lang="scss">
  .page {
    width: 100vw;
    min-height: 100vh;
    padding: 20rpx;
    box-sizing: border-box;
    font-size: 28rpx;
    background-color: #f5f5f5;
  }

  .select_box {
    display: flex;
    flex-direction: column;
    align-items: center;
    row-gap: 30rpx;
    padding-top: 140rpx;

    .tip {
      font-weight: 500;
      font-size: 30rpx;
      color: #a2aabc;
    }
    .item {
      position: relative;
      width: 660rpx;
      height: 157rpx;
      .img {
        width: 100%;
        height: 100%;
      }

      .border {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border: 3rpx solid #016bec;
        border-radius: 20rpx;
      }
    }
  }

  .next_btn {
    position: fixed;
    bottom: 80rpx;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    .btn {
      width: 537rpx;
      height: 83rpx;
      text-align: center;
      line-height: 83rpx;
      background-color: #016bec;
      color: #fff;
      font-weight: 500;
      font-size: 30rpx;
      color: #ffffff;
      border-radius: 10rpx;
    }
  }
</style>
